#     Xepec.ru - социальная сеть
#     Copyright (C) 2008  Fedorchenko Alexander <admin@xepec.ru>
#
#     This program is free software: you can redistribute it and/or modify
#     it under the terms of the GNU Affero General Public License as
#     published by the Free Software Foundation, either version 3 of the
#     License, or (at your option) any later version.
#
#     This program is distributed in the hope that it will be useful,
#     but WITHOUT ANY WARRANTY; without even the implied warranty of
#     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#     GNU Affero General Public License for more details.
#
#     You should have received a copy of the GNU Affero General Public License
#     along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
#     Autor: Fedorchenko Alexander
#     Mail: <admin@xepec.ru>
#     Date: 06/02/2010
#

require "../core.pl";
#require "../config.pl";

sub search_username
{
	#   Хеш %search_param должен быть задан до места вызова функции
	
	my $query;
	
	#my $id = "1";
	
	%search = @_;
	#$search{"sex"} = 1;
	%hcraes = reverse %search;
	
	if(keys( %hcraes ) == 1)
	{
		print qq{<error>Ваш запрос пуст!</error>};
		return 0;
	}
	if($search{"phone_country"} and $search{"phone_city"} and $search{"phone_number"})
	{
		$search{'phone'} = "+ ".$search{"phone_country"}." (".$search{"phone_city"}.") ".$search{"phone_number"};
		delete $search{"phone_country"};
		delete $search{"phone_city"};
		delete $search{"phone_number"};
	}
	if($search{"phone_number"})
	{
		$search{'phone'} = $search{"phone_number"};
		delete $search{"phone_number"};
		
	}
	
	
	
	while ( ($key,$value) = each %search )
	{
		if($value ne "")
		{
			if($query eq '')
			{
				$query = "$key LIKE '%$value%' ";
			}
			else
			{
				$query = "$query AND $key LIKE '%$value%' ";
			}
		}
	}
#	if (&queryStrig{'s'})
#	{
#	    $query = &queryString{'s'};
#	}
	$query =~ s/'/!/g;
	$query =~ s/%/%25/g;
	$query =~ s/ /%20/g;
	print qq{\n\t\t\t<query>$query</query>};
	print qq{\n\t\t\t<qquery>engine.pl?s=$query</qquery>};
	
	
#	$ath = $dbcnx->prepare(qq{SELECT * FROM username WHERE $query});
#	$ath->execute() or die("hi (error #2)");
	#@sss = $ath->fetchrow_array();
#	print qq{\n\t\t\t<result>\n};
#	while(my @sss = $ath->fetchrow_array() )
# 	{
#		print qq{\t\t\t\t<item id="@sss['0']" name="@sss['1']" foto="@sss['2']" nic="@sss['3']" status="@sss['13']" sex="@sss['5']" />\n};
#	
# 	}
#	print qq{\t\t\t</result>};







	
# 	print qq{<query>по запросу $query В разделе $cat совподение в столбце  : значение совпадения = </query>};
# 	if(@sss)
# 	{
# 		print qq{<result>};
# 		print qq{
# 			<item>id = @sss['0'] name = @sss['1'] nic = @sss['3'])</item>\n};
# 	
# 		print qq{</result>};
# 	}
# 	else
# 	{
# 		print qq{<result>};
# 		print "(<item>Ничего не найдено((</item>\n";
# 	
# 		print qq{<result>};
# 	}



	#<item name="$nazvanie" href="/groups/index.pl?uname=$uname_id&amp;gr&#61;$id" />};
        
        #$sss = $re->fetchrow_array();
        #print $sss;
        $ath->finish();
        $dbcnx->disconnect();
	#return @arr;
}

sub search_username_new
{
	
}
